#ifndef DBHELPER_H
#define DBHELPER_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QJsonArray>
#include<QUuid>
#include "messagepackage.h"

class dbhelper
{
public:
    static dbhelper *getInstance();
    static void removeInstance();

    // 用户相关
    void setOnlineStatus(QString name,bool status);
    bool userRegist(QString name,QString pswd);
    bool userLogin(QString name,QString pswd);

    // 讨论组相关
    QString createGroup( const  QString &name,const  QString &creator);
    bool addGroupMember(const  QString &groupId, const QString &memberName);
    QJsonArray getGroupList(const QString &username);
    QJsonArray getGroupMembers(const QString &groupId);
    bool isGroupMember(const QString &groupId, const QString &memberName);
    QString getGroupName(const QString &groupId);

private:
    dbhelper();
    ~dbhelper();
    static dbhelper* instance;
    QSqlDatabase db;

    void initUserTable();
    void initGroupTables();
};

#endif // DBHELPER_H
